package com.study.web.controller.goal;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.study.common.core.controller.AppBaseController;
import com.study.common.core.domain.PageQuery;
import com.study.common.core.domain.R;
import com.study.common.core.page.TableDataInfo;
import com.study.goal.domain.bo.PlanBo;
import com.study.goal.domain.vo.PlanVo;
import com.study.goal.service.IPlanService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;

/**
 * 学习计划
 *
 * @author MT
 * @date 2025-09-03
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/plans")
public class PlanController extends AppBaseController {

    private final IPlanService planService;

    /**
     * 查询所有计划列表
     * @param bo 查询参数
     * @param pageQuery 分页参数
     * @return
     */
    @SaCheckLogin
    @GetMapping("/list")
    public TableDataInfo<PlanVo> list(PlanBo bo, PageQuery pageQuery) {
        return planService.queryPageList(bo, pageQuery);
    }


    /**
     * 查询计划列表
     * @param goalId
     * @param pageQuery
     * @return
     */
    @SaCheckLogin
    @GetMapping("/listById")
    public TableDataInfo<PlanVo> listById(Long goalId, PageQuery pageQuery) {
        return planService.queryPageListById(goalId, pageQuery);
    }

    /**
     * 获取计划详细信息
     * @param id
     * @return
     */
    @SaCheckLogin
    @GetMapping("/{id}")
    public R<PlanVo> getInfo(@PathVariable("id") Long id) {
        return R.ok(planService.queryById(id));
    }

    /**
     * 新增计划
     * @param bo
     * @return
     */
    @SaCheckLogin
    @PostMapping("/add")
    public R<Void> addPlan(@Validated @RequestBody PlanBo bo) {
        return toAjax(planService.insertByBo(bo));
    }

    /**
     * 修改计划
     * @param bo
     * @return
     */
    @SaCheckLogin
    @PostMapping("/edit")
    public R<Void> editPlan(@Validated @RequestBody PlanBo bo) {
        return toAjax(planService.updateByBo(bo));
    }

    /**
     * 删除计划
     * @param id
     * @return
     */
    @SaCheckLogin
    @DeleteMapping("/{id}")
    public R<Void> delete(@PathVariable Long id) {
        return toAjax(planService.deleteWithValidById(id,false));
    }
}
